async function scheduleTimer({
    providerRes,
    parserRes
} = {}) {
    await loadTool('AIScheduleTools')

    let forToken = 'http://njw.xjistedu.cn:8100/xjlgxyhd/loginSso?toMenu=xs_kcb'
    let token = get(forToken)
    token = token.substring(token.indexOf('token=') + 6, token.indexOf('&'))
    log('token', token)
    let forWeek = 'http://njw.xjistedu.cn:8100/xjlgxyhd/teachingWeek'
    let week = post(forWeek, token)
    week = JSON.parse(week)['data']
    week = week.length
    log('总周数', week)

    await AIScheduleAlert('接下来是作息时间设定')

    const firstSectionTime = await AISchedulePrompt({
        titleText: '一、第一课开始时间',
        tipText: '1.偶数号楼比奇数号楼晚半个小时\n2.每天作息只能一样，所以建议看第一节是哪种号楼的多填哪种\n3.时间写法为xx:xx格式，不能少位，不足前补零，如09:09\n4.默认10:00',
        defaultText: '10:00',
        validator: value => {
            console.log(value)
            if (value.length != 5 || value.indexOf(':') != 2) return '格式不正确，确定是如09:09的格式吗'
            return false
        }
    })

    const secondSectionTime = await AISchedulePrompt({
        titleText: '二、第二课开始时间',
        tipText: '1.第二节课时间也不确定，需要自己填写\n2.时间写法为xx:xx格式，不能少位，不足前补零，如09:09\n3.默认12:10',
        defaultText: '12:10',
        validator: value => {
            console.log(value)
            if (value.length != 5 || value.indexOf(':') != 2) return '格式不正确，确定是如09:09的格式吗'
            return false
        }
    })

    const thirdSectionTime = await AISchedulePrompt({
        titleText: '三、第三课开始时间',
        tipText: '1.大概四节大课，干脆每节确定一下开始时间\n2.时间写法为xx:xx格式，不能少位，不足前补零，如09:09\n3.默认16:00',
        defaultText: '16:00',
        validator: value => {
            console.log(value)
            if (value.length != 5 || value.indexOf(':') != 2) return '格式不正确，确定是如09:09的格式吗'
            return false
        }
    })

    const fourthSectionTime = await AISchedulePrompt({
        titleText: '四、第四课开始时间',
        tipText: '1.默认18:00',
        defaultText: '18:00',
        validator: value => {
            console.log(value)
            if (value.length != 5 || value.indexOf(':') != 2) return '格式不正确，确定是如09:09的格式吗'
            return false
        }
    })

    const fifthSectionTime = await AISchedulePrompt({
        titleText: '五、第五课开始时间',
        tipText: '1.默认20:30',
        defaultText: '20:30',
        validator: value => {
            console.log(value)
            if (value.length != 5 || value.indexOf(':') != 2) return '格式不正确，确定是如09:09的格式吗'
            return false
        }
    })

    const sixthSectionTime = await AISchedulePrompt({
        titleText: '六、第六课开始时间',
        tipText: '1.默认99:99(不记录)\n2.虽然暂且没见识过第六节的课',
        defaultText: '99:99',
        validator: value => {
            console.log(value)
            if (value.length != 5 || value.indexOf(':') != 2) return '格式不正确，确定是如09:09的格式吗'
            return false
        }
    })

    const sectionTime = await AISchedulePrompt({
        titleText: '七、课程时长',
        tipText: '1.因为不确定会不会变\n2.默认45分钟',
        defaultText: '45',
        validator: value => {
            console.log(value)
            if (!isNum(parseInt(value))) return '只能是数字，单位分钟'
            return false
        }
    })

    //学期开始日期时间戳
    providerRes = eval(providerRes)
    let date = JSON.parse(providerRes[0])[0]['date']
    log('date', date)
    date = date[0]['mxrq']
    let startSemester = new Date(Date.parse(date)).getTime().toString()
    log('startSemester', startSemester)

    let sections = [],
        startTime = firstSectionTime,
        endTime = plusTime(startTime, sectionTime)
    sections.push({
        section: 1,
        startTime: startTime,
        endTime: endTime,
    })
    startTime = plusTime(endTime, 10)
    endTime = plusTime(startTime, sectionTime)
    sections.push({
        section: 2,
        startTime: startTime,
        endTime: endTime,
    })

    startTime = secondSectionTime
    endTime = plusTime(startTime, sectionTime)
    sections.push({
        section: 3,
        startTime: startTime,
        endTime: endTime,
    })
    startTime = plusTime(endTime, 10)
    endTime = plusTime(startTime, sectionTime)
    sections.push({
        section: 4,
        startTime: startTime,
        endTime: endTime,
    })

    startTime = thirdSectionTime
    endTime = plusTime(startTime, sectionTime)
    sections.push({
        section: 5,
        startTime: startTime,
        endTime: endTime,
    })
    startTime = plusTime(endTime, 10)
    endTime = plusTime(startTime, sectionTime)
    sections.push({
        section: 6,
        startTime: startTime,
        endTime: endTime,
    })

    startTime = fourthSectionTime
    endTime = plusTime(startTime, sectionTime)
    sections.push({
        section: 7,
        startTime: startTime,
        endTime: endTime,
    })
    startTime = plusTime(endTime, 10)
    endTime = plusTime(startTime, sectionTime)
    sections.push({
        section: 8,
        startTime: startTime,
        endTime: endTime,
    })

    startTime = fifthSectionTime
    endTime = plusTime(startTime, sectionTime)
    sections.push({
        section: 9,
        startTime: startTime,
        endTime: endTime,
    })
    startTime = plusTime(endTime, 10)
    endTime = plusTime(startTime, sectionTime)
    sections.push({
        section: 10,
        startTime: startTime,
        endTime: endTime,
    })

    let nightCourse = 2
    if (sixthSectionTime != '99:99') {
        nightCourse += 2
        startTime = sixthSectionTime
        endTime = plusTime(startTime, sectionTime)
        sections.push({
            section: 11,
            startTime: startTime,
            endTime: endTime,
        })
        startTime = plusTime(endTime, 10)
        endTime = plusTime(startTime, sectionTime)
        sections.push({
            section: 12,
            startTime: startTime,
            endTime: endTime,
        })
    }




    // 返回时间配置JSON，所有项都为可选项，如果不进行时间配置，请返回空对象
    return {
        totalWeek: week, // 总周数：[1, 30]之间的整数
        startSemester: startSemester, // 开学时间：时间戳，13位长度字符串，推荐用代码生成
        startWithSunday: false, // 是否是周日为起始日，该选项为true时，会开启显示周末选项
        showWeekend: true, // 是否显示周末
        forenoon: 4, // 上午课程节数：[1, 10]之间的整数
        afternoon: 4, // 下午课程节数：[0, 10]之间的整数
        night: nightCourse, // 晚间课程节数：[0, 10]之间的整数
        sections: sections
            /* [{
                        section: 1, // 节次：[1, 30]之间的整数
                        startTime: '08:00', // 开始时间：参照这个标准格式5位长度字符串
                        endTime: '08:50', // 结束时间：同上
                    }] */
            , // 课程时间表，注意：总长度要和上边配置的节数加和对齐
    }
    // PS: 夏令时什么的还是让用户在夏令时的时候重新导入一遍吧，在这个函数里边适配吧！奥里给！————不愿意透露姓名的嘤某人
}

//时间增加
function plusTime(timeStr, plusMins) {
    let time = timeStr.split(':')
    let hours = Number(time[0])
    let minutes = Number(time[1])
    let sixty = Number(60)
    log('hours', hours)
    log('minutes', minutes)
    minutes = minutes + Number(plusMins)
    log('minutes', minutes)
    if (minutes >= sixty) {
        minutes = minutes - sixty
        hours++
    }
    hours = hours.toString()
    minutes = minutes.toString()
    if (hours.length != 2) hours = '0' + hours
    if (minutes.length != 2) minutes = '0' + minutes
    let result = hours + ':' + minutes
    log('plusTime', result)
    return result
}

function get(url) {
    let xhr = new XMLHttpRequest()
    xhr.open('GET', url, false)
    xhr.send()
    return xhr.responseText
}

function post(url, token) {
    let xhr = new XMLHttpRequest()
    xhr.open('POST', url, false)
        //xhr.setRequestHeader("Access-Control-Allow-Origin", "*")
    xhr.setRequestHeader('token', token)
    xhr.send()
    return xhr.responseText
}


//是否为数字
function isNum(value) {
    return (typeof value === 'number' && !isNaN(value));
}

function log(tag, ct) {
    if (ct == undefined)
        console.info(tag)
    else
        console.info(tag, ct)
}